const TotalCols = 4;
const TotalRows = 3;

const PrecisionUnits = 0.6;

// TODO: This is still different from the MappingExtension in ArcViewer!!!
function adjustPrecision(value){
  if(Math.abs(value) >= 1000){
    value -= 1000 * Math.sign(value);
    value /= 1000;
  }
  return value;
}

let MaterialCache = {}
const GameConfig = {
  NoteExistTime: 0.975,
  BirthDistance: 10,
  DieDistance: 2,
  GetNoteSpeed: function(){
    return (this.BirthDistance + this.DieDistance) / this.NoteExistTime
  },
  GetTotalCubeExistTime: function() {
    return this.BirthDistance + this.DieDistance
  },
  GridSpacing: 1.25,
  PlayerPosition: [0,1.5,0],
  CameraPosition: [0,0,5],
  LeftSaberColor: 0xff0000, // Red
  RightSaberColor: 0x0000ff, // Blue
  GetSaberMaterial: function(THREE, type){ // type: 0 -- Left, 1 -- Right
    if(MaterialCache[type])
      return MaterialCache[type]
    
    const _this = this
    MaterialCache[type] = new THREE.MeshStandardMaterial({
      color: type == 0? _this.LeftSaberColor: _this.RightSaberColor
    })
    return MaterialCache[type]
  },
  GetGridPositionXY: function(col, row){
    col = adjustPrecision(col)
    row = adjustPrecision(row)

    const xStart = this.PlayerPosition[0] - (TotalCols - 1) * this.GridSpacing / 2;
    const yStart = -this.PlayerPosition[1];

    const result = [
      xStart + col * this.GridSpacing,
      yStart + row * this.GridSpacing,
    ]
    return result;
  }
}

export {GameConfig}